package me.gerry.locktest.monitor;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import me.gerry.locktest.manager.FloatViewMgr;
import me.gerry.locktest.manager.KeyGuardLocker;
import me.gerry.locktest.util.Global;

/**
 * Created by gerry on 2018/6/24.
 */

public class ScreenOffMonitor extends Monitor {

    public ScreenOffMonitor(Context context) {
        super(context);
    }

    @Override
    public void register() {
        IntentFilter filter = new IntentFilter();
        filter.setPriority(1000);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        getContext().registerReceiver(this, filter);
    }

    @Override
    public void onReceive(Context context, Intent intent) {

        Context application = Global.getContext();
        FloatViewMgr.getInstance().initWindowManager(application);
        FloatViewMgr.getInstance().showFloatView(application);

        if (KeyGuardLocker.getInstance(application).inKeyguardRestrictedInputMode()){
            KeyGuardLocker.getInstance(application).disableKeyGuard();
        }
    }
}
